//定义管理员store
import {defineStore} from 'pinia'
import {ref} from 'vue'

export const useAdminStore = defineStore('admin',()=>{
    //定义状态的内容

    //1.响应式变量 - 管理员信息
    const adminInfo = ref({})

    //2.定义一个函数,设置管理员信息
    const setAdminInfo = (newAdminInfo)=>{
        adminInfo.value = newAdminInfo
    }

    //3.函数,获取管理员姓名
    const getAdminName = ()=>{
        return adminInfo.value.realName || adminInfo.value.username || '管理员'
    }

    //4.函数,获取管理员ID
    const getAdminId = ()=>{
        return adminInfo.value.id
    }

    //5.函数,清除管理员信息
    const clearAdminInfo = ()=>{
        adminInfo.value = {}
    }

    return {
        adminInfo,
        setAdminInfo,
        getAdminName,
        getAdminId,
        clearAdminInfo
    }
},{
    persist: true
});